//部分控制器
var app = angular.module('myApp.controllers');

//example首页
app.controller('licenseIndex', ["$scope", "utilService", "$rootScope", function ($scope, utilService, $rootScope) {
  // 模拟数据
  $scope.licenseList = [
    {id: '1', isEdit: false,isDefalut:true},
    {id: '2', isEdit: false}
  ]
  //点击去编辑
  $scope.toEdit = function (index) {
    $scope.licenseList[index]['isEdit'] = true;
  }
  // 点击去详情
  $scope.toDetail = function (index, id) {
    if ($scope.licenseList[index]['isEdit']) {
      $scope.licenseList[index]['isEdit'] = false;
    } else {
      //跳转至详情
      licenseDetail = $scope.licenseList[index];
      utilService.$state.go('car.add', {edit: 1});
    }
  }
  /*点击取消编辑*/
  $scope.cancelFocus = function (index){
    $scope.licenseList[index].isEdit = false;
  }
  /*设置默认*/
  $scope.setDefault = function (index) {
    $scope.licenseList.forEach(function (t,$index) {
      if(index==$index){
        t.isDefalut = true;
      }else{
        t.isDefalut = false;
      }
    })
    $scope.licenseList[index].isDefalut = true;
  }

  $scope.$on('$ionicView.beforeEnter', function () {
    //页面刚加载
    utilService.$ionicLoading.show(HX_CONFIG.loadingBase);
  }, false);
  $scope.$on('$ionicView.afterEnter', function () {
    utilService.$rootScope.rootData.title = '驾照管理';
    //页面加载完成
    utilService.$ionicLoading.hide();
  }, false);
  $rootScope.$on('$ionicView.beforeLeave', function (e, ion) {
    //页面离开之前
    //alertPopup && alertPopup.close();

  }, false);


}]);
app.controller('licenseAdd', ["$scope", "utilService", "$rootScope", function ($scope, utilService, $rootScope) {

  $scope.title = '编辑驾照';
  $scope.alert = false;//控制弹窗
  $scope.alertIndex = 1;
  /*点击提示*/
  $scope.showAlert = function (index) {
    $scope.alertIndex = index;
    $scope.alert = true;
  }
  /*关闭提示*/
  $scope.closeAlert = function (index) {
    $scope.alert = false;
  }

  $scope.$on('$ionicView.beforeEnter', function () {
    //页面刚加载
    utilService.$ionicLoading.show(HX_CONFIG.loadingBase);
  }, false);
  $scope.$on('$ionicView.afterEnter', function () {
    utilService.$rootScope.rootData.title = $scope.title;
    //页面加载完成
    utilService.$ionicLoading.hide();
  }, false);
  $rootScope.$on('$ionicView.beforeLeave', function (e, ion) {
    //页面离开之前
    //alertPopup && alertPopup.close();

  }, false);

}]);
app.factory('licenseDetail', function () {
  return {}
})